<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/googleapis/0.0.2/googleapis.min.js"></script>
  <script>
  
  function discovery() {
    googleapis.load('buzz', 'v1', function(resp) { alert('API loaded'); });
  }

  function printResponse(msg) {
    if (typeof(msg) === 'object') {
      // TODO: Fix this for browsers without JSON
      msg = JSON.stringify(msg);
    }
    document.getElementById('response').value = msg;
  }

  function callback(resp) {
    var error = null;
    if ('error' in resp) {
      error = resp['error'];
    }
    if (error) {
      printResponse('ERROR ' + error.code + ': ' + error.message);
      return;
    }
    printResponse(resp);
  }

  function makeRequest() {
    chili.activities.search({'q': 'homer'}).execute(callback);
  }
  </script>
</head>
<body>
<a href="javascript:void(0);" onclick="discovery();">Load the Buzz API from Discovery</a><br />
<a href="javascript:void(0);" onclick="makeRequest();">Search Buzz for 'homer'</a><br /><br />
<div>
<b>Response</b><br />
<textarea id="response" style="width: 500px; height: 500px;"></textarea>
</div>
</body>
</html>
